package cn.nnb.control.cy;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.snow.order.biz.FoodBiz;
import com.snow.order.log.Log;

public class image extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public image() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
        FoodBiz foodbiz=new FoodBiz();
        
        int fid = 0;
		try {
			fid = Integer.parseInt(request.getParameter("fid"));
		} catch (NumberFormatException e1) {
			
			//e1.printStackTrace();
		}
        System.out.println(fid);
        byte[] bt=null;
        try {
			bt=foodbiz.getPic(fid);
			if(bt!=null)
			{
			  ServletOutputStream out=response.getOutputStream();
			  out.write(bt);
			  out.flush();
			  out.close();
			}
			
		} catch (Exception e) {
			Log.logger.error(e.getMessage());
			e.printStackTrace();
		}
		
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
